package com.geezdata.cps.ttk.integration.common.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.geezdata.cps.base.utils.HttpClientUtil;
import com.geezdata.cps.ttk.integration.common.CommonIntegrationService;

@Service
public class CommonIntegrationServiceImpl implements CommonIntegrationService{
	private static final Logger logger = LoggerFactory.getLogger(CommonIntegrationServiceImpl.class);
	
	@Override
	public boolean request(String url, String params) {
		String rspStr = null;
        try {
        	rspStr = HttpClientUtil.post(url, params, true);
        } catch (Exception e) {
        	rspStr = null;
        }
        
        if (rspStr == null) {
			logger.error("Common request url {}", url);
        	logger.error("Common request {}", params);
        	return false;
		}
        JSONObject jsonObject = JSONObject.parseObject(rspStr);
        if(jsonObject.getBoolean("success") == null || !jsonObject.getBoolean("success")) {
        	logger.info("Common request url {}", url);
        	logger.info("Common request {}", params);
        	return false;
        }
		return true;
	}
}
